Skip to contentSkip to conversation

Change in openvpn[master]: dco-win: factor out getting dco version info own function

Openvpn-devel In review stipa (Code Review) 2 participants 14 messages Sep 6, 2024 – Dec 29, 2024 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1725608632000.I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7@...2715...

#1 lore raw

Attention is currently required from: flichtenheld, plaisthos.

Hello plaisthos, flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/733?usp=email

to review the following change.

Change subject: dco-win: factor out getting dco version info own function
......................................................................

dco-win: factor out getting dco version info own function

Instead of having duplicated code to get dco version for data_v3 checks and for version info, have it in one place and store the version in dco context - the latter is a preparation for dco v2 support (multi-peer).

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

---
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h

2 files changed, 51 insertions(+), 56 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/1

src/openvpn/dco_win.c +50 -56
index 189864b..cf825b3 100644
@@ -52,11 +52,54 @@
     return tt;
 }
 
+static void
+dco_get_version(OVPN_VERSION *version)
+{
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+}
+
+static inline
+bool
+dco_version_supports_data_v3(OVPN_VERSION *version)
+{
+    return (version->Major > 1) || (version->Minor >= 4);
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
-    dco->supports_data_v3 = dco_supports_data_v3(NULL);
-    msg(D_DCO_DEBUG, "dco supports data_v3: %d", dco->supports_data_v3);
+    dco_get_version(&dco->version);
+    dco->supports_data_v3 = dco_version_supports_data_v3(&dco->version);
+
+    msg(D_DCO_DEBUG, "dco data_v3: %d", dco->supports_data_v3);
 
     return true;
 }
@@ -428,33 +471,9 @@
 dco_version_string(struct gc_arena *gc)
 {
     OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
+    ZeroMemory(&version, sizeof(version));
 
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
-    {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
-    }
-
-    if (h == INVALID_HANDLE_VALUE)
-    {
-        return "N/A";
-    }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
+    dco_get_version(&version);
 
     struct buffer out = alloc_buf_gc(256, gc);
     buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
@@ -538,36 +557,11 @@
 bool
 dco_supports_data_v3(struct context *c)
 {
-    bool res = false;
-
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
-    {
-        goto done;
-    }
-
     OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
+    ZeroMemory(&version, sizeof(version));
+    dco_get_version(&version);
 
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        goto done;
-    }
-
-    /* data_v3 is supported starting from 1.4 */
-    res = (version.Major > 1) || (version.Minor >= 4);
-
-done:
-    if (h != INVALID_HANDLE_VALUE)
-    {
-        CloseHandle(h);
-    }
-
-    return res;
+    return dco_version_supports_data_v3(&version);
 }
 
 #endif /* defined(_WIN32) */
src/openvpn/dco_win.h +1 -0
index f58488f..ce57817 100644
@@ -34,6 +34,7 @@
 struct dco_context {
     struct tuntap *tt;
     bool supports_data_v3;
+    OVPN_VERSION version;
 };
 
 typedef struct dco_context dco_context_t;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version info own function
......................................................................

Patch Set 1:

(5 comments)

Patchset:

PS1:
Overall the factoring-out looks good, but there's one textual change that I find to be "less clear now", and a few remarks.

File src/openvpn/dco_win.c:

http://gerrit.openvpn.net/c/openvpn/+/733/comment/728ea9f7_3e755e74 :
PS1, Line 102: msg(D_DCO_DEBUG, "dco data_v3: %d", dco->supports_data_v3);
I think keeping the "supports" here (= not changing the text) would ease understanding of the logs.

http://gerrit.openvpn.net/c/openvpn/+/733/comment/69aa1495_3d39dec2 :
PS1, Line 474: ZeroMemory(&version, sizeof(version));
CLEAR(version) exists (if you change this line anyway).

Or just zeroize on assign OVPN_VERSION = {0}?

http://gerrit.openvpn.net/c/openvpn/+/733/comment/4fdb9c97_bc7702f6 :
PS1, Line 481: return BSTR(&out);
technically this does something else if no DCO driver can be found - the old code returns "N/A", the new code returns "0.0.0". Is this intentional?

http://gerrit.openvpn.net/c/openvpn/+/733/comment/bd3ba22f_ce91aaf0 :
PS1, Line 562: dco_get_version(&version);
see above wrt CLEAR() or = {0}

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Mon, 09 Sep 2024 14:30:15 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos, stipa.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/733?usp=email

to look at the new patch set (#2).

Change subject: dco-win: factor out getting dco version info own function
......................................................................

dco-win: factor out getting dco version info own function

Instead of having duplicated code to get dco version for data_v3 checks and for version info, have it in one place and store the version in dco context - the latter is a preparation for dco v2 support (multi-peer).

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

---
M src/openvpn/dco_win.c
M src/openvpn/dco_win.h

2 files changed, 71 insertions(+), 58 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/2

src/openvpn/dco_win.c +70 -58
index 189864b..349b45a 100644
@@ -52,10 +52,70 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passes OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
+static inline
+bool
+dco_version_supports_data_v3(OVPN_VERSION *version)
+{
+    return (version->Major > 1) || (version->Minor >= 4);
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
-    dco->supports_data_v3 = dco_supports_data_v3(NULL);
+    (void)dco_get_version(&dco->version);
+    dco->supports_data_v3 = dco_version_supports_data_v3(&dco->version);
+
     msg(D_DCO_DEBUG, "dco supports data_v3: %d", dco->supports_data_v3);
 
     return true;
@@ -427,39 +487,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int
@@ -538,36 +576,10 @@
 bool
 dco_supports_data_v3(struct context *c)
 {
-    bool res = false;
+    OVPN_VERSION version = {0};
+    (void)dco_get_version(&version);
 
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
-    {
-        goto done;
-    }
-
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        goto done;
-    }
-
-    /* data_v3 is supported starting from 1.4 */
-    res = (version.Major > 1) || (version.Minor >= 4);
-
-done:
-    if (h != INVALID_HANDLE_VALUE)
-    {
-        CloseHandle(h);
-    }
-
-    return res;
+    return dco_version_supports_data_v3(&version);
 }
 
 #endif /* defined(_WIN32) */
src/openvpn/dco_win.h +1 -0
index f58488f..ce57817 100644
@@ -34,6 +34,7 @@
 struct dco_context {
     struct tuntap *tt;
     bool supports_data_v3;
+    OVPN_VERSION version;
 };
 
 typedef struct dco_context dco_context_t;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version info own function
......................................................................

Patch Set 2:

(4 comments)

File src/openvpn/dco_win.c:

http://gerrit.openvpn.net/c/openvpn/+/733/comment/8f07dbeb_507f5019 :
PS1, Line 102: msg(D_DCO_DEBUG, "dco data_v3: %d", dco->supports_data_v3);

Quoted 1 line

I think keeping the "supports" here (= not changing the text) would ease understanding of the logs.

Acknowledged

http://gerrit.openvpn.net/c/openvpn/+/733/comment/3508d8c9_0dd6626f :
PS1, Line 474: ZeroMemory(&version, sizeof(version));

Quoted 1 line

CLEAR(version) exists (if you change this line anyway). […]

Agreed. Will use = {0} here and also CLEAN() within get_version() itself to make sure it zeroes fields and doesn't depend on the caller.

http://gerrit.openvpn.net/c/openvpn/+/733/comment/d5b2be96_d092b75d :
PS1, Line 481: return BSTR(&out);

Quoted 1 line

technically this does something else if no DCO driver can be found - the old code returns "N/A", the […]

Good point, other platforms return "N/A", will bring it back.

http://gerrit.openvpn.net/c/openvpn/+/733/comment/e42a0200_3120a0fe :
PS1, Line 562: dco_get_version(&version);

Quoted 1 line

see above wrt CLEAR() or = {0}

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 10 Sep 2024 09:17:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version info own function
......................................................................

Patch Set 2: Code-Review+2

(1 comment)

Patchset:

PS2:
looks good to me. will process after the meetup when the prerequisite patches are merged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 2
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Wed, 11 Sep 2024 13:19:53 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#6 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/733?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Code-Review+2 by cron2

The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.

Change subject: dco-win: factor out getting dco version
......................................................................

dco-win: factor out getting dco version

As a preparation for multipeer and data_v3,
add function which returns dco version in
machine-readable format.

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

---
M src/openvpn/dco_win.c

1 file changed, 57 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/3

src/openvpn/dco_win.c +57 -28
index 9224bca..27182b5 100644
@@ -52,6 +52,57 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passes OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
@@ -386,39 +437,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset

#7 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

Attention is currently required from: cron2, plaisthos, stipa.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version
......................................................................

Patch Set 3: Code-Review+2

(1 comment)

File src/openvpn/dco_win.c:

http://gerrit.openvpn.net/c/openvpn/+/733/comment/0308e253_5a915e25 :
PS3, Line 58: * Fills Major/Minor/Patch fields in a passes OVPN_VERSION Typo "passed"

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 3
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Fri, 22 Nov 2024 14:29:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#8 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos, stipa.

Hello cron2, flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/733?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.

Change subject: dco-win: factor out getting dco version
......................................................................

dco-win: factor out getting dco version

As a preparation for multipeer and data_v3,
add function which returns dco version in
machine-readable format.

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

---
M src/openvpn/dco_win.c

1 file changed, 57 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/4

src/openvpn/dco_win.c +57 -28
index 9224bca..f59bf8c 100644
@@ -52,6 +52,57 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passed OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
@@ -386,39 +437,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 4
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-MessageType: newpatchset

#9 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

Attention is currently required from: cron2, flichtenheld, plaisthos.

stipa has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version
......................................................................

Patch Set 4:

(1 comment)

File src/openvpn/dco_win.c:

http://gerrit.openvpn.net/c/openvpn/+/733/comment/7074ea5d_02f36947 :
PS3, Line 58: * Fills Major/Minor/Patch fields in a passes OVPN_VERSION

Quoted 1 line

Typo "passed"

Acknowledged

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 4
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 22 Nov 2024 15:45:10 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Gerrit-MessageType: comment

#10 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos, stipa.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version
......................................................................

Patch Set 5: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 5
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: stipa <[email protected]...>
Gerrit-Comment-Date: Sun, 29 Dec 2024 14:17:40 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#11 lore raw

PATCH v5 1/1 dco-win: factor out getting dco version

In reply to a message not in the archive

From: Lev Stipakov <[email protected]...>

As a preparation for multipeer and data_v3,
add function which returns dco version in
machine-readable format.

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/733
This mail reflects revision 5 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

src/openvpn/dco_win.c +57 -28
index 9224bca..f59bf8c 100644
@@ -52,6 +52,57 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passed OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
@@ -386,39 +437,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int
#12 lore raw

[Openvpn-devel] [PATCH applied] Re: dco-win: factor out getting dco version

Stared at code, had a few issues, those all got addressed. Stared again today (looks good). Test compiled on Ubuntu/MinGW, claims its happy.

Your patch has been applied to the master branch.

commit 10e785f1dcacdfd5240ac18a53f2839b4d3b979c (master)

Author: Lev Stipakov
Date:   Sun Dec 29 15:17:59 2024 +0100
     dco-win: factor out getting dco version

     Signed-off-by: Lev Stipakov <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg30297.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#13 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

cron2 has uploaded a new patch set (#6) to the change originally created by stipa. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: dco-win: factor out getting dco version
......................................................................

dco-win: factor out getting dco version

As a preparation for multipeer and data_v3,
add function which returns dco version in
machine-readable format.

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30297.html

---
M src/openvpn/dco_win.c

1 file changed, 57 insertions(+), 28 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/33/733/6

src/openvpn/dco_win.c +57 -28
index 9224bca..f59bf8c 100644
@@ -52,6 +52,57 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passed OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
@@ -386,39 +437,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 6
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#14 lore raw

[Openvpn-devel] [M] Change in openvpn[master]: dco-win: factor out getting dco version

In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/733?usp=email )

Change subject: dco-win: factor out getting dco version
......................................................................

dco-win: factor out getting dco version

As a preparation for multipeer and data_v3,
add function which returns dco version in
machine-readable format.

Change-Id I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30297.html

---
M src/openvpn/dco_win.c

1 file changed, 57 insertions(+), 28 deletions(-)
src/openvpn/dco_win.c +57 -28
index 9224bca..f59bf8c 100644
@@ -52,6 +52,57 @@
     return tt;
 }
 
+/**
+ * Gets version of dco-win driver
+ *
+ * Fills Major/Minor/Patch fields in a passed OVPN_VERSION
+ * struct. If version cannot be obtained, fields are set to 0.
+ *
+ * @param version pointer to OVPN_VERSION struct
+ * @returns true if version has been obtained, false otherwise
+ */
+static bool
+dco_get_version(OVPN_VERSION *version)
+{
+    CLEAR(*version);
+
+    bool res = false;
+
+    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
+                          0, NULL, OPEN_EXISTING, 0, NULL);
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        /* fallback to a "normal" device, this will fail if device is already in use */
+        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
+                       0, NULL, OPEN_EXISTING, 0, NULL);
+    }
+
+    if (h == INVALID_HANDLE_VALUE)
+    {
+        goto done;
+    }
+
+    DWORD bytes_returned = 0;
+    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
+                         version, sizeof(*version), &bytes_returned, NULL))
+    {
+        goto done;
+    }
+
+    res = true;
+
+done:
+    if (h != INVALID_HANDLE_VALUE)
+    {
+        CloseHandle(h);
+    }
+
+    msg(D_DCO_DEBUG, "dco version: %ld.%ld.%ld", version->Major, version->Minor, version->Patch);
+
+    return res;
+}
+
 bool
 ovpn_dco_init(int mode, dco_context_t *dco)
 {
@@ -386,39 +437,17 @@
 const char *
 dco_version_string(struct gc_arena *gc)
 {
-    OVPN_VERSION version;
-    ZeroMemory(&version, sizeof(OVPN_VERSION));
-
-    /* first, try a non-exclusive control device, available from 1.3.0 */
-    HANDLE h = CreateFile("\\\\.\\ovpn-dco-ver", GENERIC_READ,
-                          0, NULL, OPEN_EXISTING, 0, NULL);
-
-    if (h == INVALID_HANDLE_VALUE)
+    OVPN_VERSION version = {0};
+    if (dco_get_version(&version))
     {
-        /* fallback to a "normal" device, this will fail if device is already in use */
-        h = CreateFile("\\\\.\\ovpn-dco", GENERIC_READ,
-                       0, NULL, OPEN_EXISTING, 0, NULL);
+        struct buffer out = alloc_buf_gc(256, gc);
+        buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
+        return BSTR(&out);
     }
-
-    if (h == INVALID_HANDLE_VALUE)
+    else
     {
         return "N/A";
     }
-
-    DWORD bytes_returned = 0;
-    if (!DeviceIoControl(h, OVPN_IOCTL_GET_VERSION, NULL, 0,
-                         &version, sizeof(version), &bytes_returned, NULL))
-    {
-        CloseHandle(h);
-        return "N/A";
-    }
-
-    CloseHandle(h);
-
-    struct buffer out = alloc_buf_gc(256, gc);
-    buf_printf(&out, "%ld.%ld.%ld", version.Major, version.Minor, version.Patch);
-
-    return BSTR(&out);
 }
 
 int

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/733?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8e8ddd35bd3cc3334faf7f57118d1892512ae9f7
Gerrit-Change-Number: 733
Gerrit-PatchSet: 6
Gerrit-Owner: stipa <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged